﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLTV_V2.DataAccess;

namespace QLTV_V2
{
    public partial class frmReportPhieuKK : Form
    {
        public frmReportPhieuKK()
        {
            InitializeComponent();
        }
        ConnectData conn = new ConnectData();
        public string maphieuKK, maphieuTL, maphieuDT;
        public int dk;
        public DataTable dtb=new DataTable();
        //DataTable dtb = new DataTable();
        private void frmReportPhieuKK_Load(object sender, EventArgs e)
        {
            if (dk == 1)//Report phiếu kiểm kê
            {
                dtb = getSource_KiemKe(maphieuKK);
                CRT_PhieuKiemKe CR = new CRT_PhieuKiemKe();
                CR.SetDataSource(dtb);
                crystalReportViewer1.ReportSource = CR;
            }
            if (dk == 2)//Report phiếu thanh lý
            {
                dtb = getSource_ThanhLy(maphieuTL);
                CRT_PhieuTL cr = new CRT_PhieuTL();
                cr.SetDataSource(dtb);
                crystalReportViewer1.ReportSource = cr;
            }
            if (dk == 3) //Report dự toán mua sách
            {
                dtb = getSource_DuToan(maphieuDT);
                CRT_PhieuDT cr = new CRT_PhieuDT();
                cr.SetDataSource(dtb);
                crystalReportViewer1.ReportSource = cr;
            }
            if (dk == 4)//Report thống kê sách
            {
                CRT_ThongkeSach crt = new CRT_ThongkeSach();
                crt.SetDataSource(dtb);
                crystalReportViewer1.ReportSource = crt;
            }
        }
        DataTable getSource_KiemKe(string maphieukk)
        {
            string sql = "select b.MaPhieuKK, Upper(TenPhieuKK) as TenPhieuKK,NgayKK,TenNV,d.MaBanSach, TenDauSach,NamXB, TenTacGia,TinhTrang, TenLoaiSach " +
                        "from NhanVien a join PhieuKiemKe b on a.MaNV=b.MaNV " +
                        "join CTKiemKe c on b.MaPhieuKK=c.MaPhieuKK " +
                        "join BanSach d on c.MaBanSach=d.MaBanSach " +
                        "join DauSach e on d.MaDauSach=e.MaDauSach " +
                        "join TacGia f on e.MaTacGia=f.MaTacGia " +
                        "join LoaiSach g on e.MaLoaiSach=g.MaLoaiSach "+
                        "where b.MaPhieuKK=N'" + maphieukk + "' " +
                        "order by d.MaBanSach";
            return conn.GetDataTable(sql);
        }
        DataTable getSource_ThanhLy(string maphieutl)
        {
            string sql = "select b.MaPhieuTL, Upper(TenPhieuTL) as TenPhieuTL, NgayTL, TenNV, TenLoaiSach,d.MaBanSach,TenDauSach,TenTacGia,NamXB,TinhTrang " +
                         "from NhanVien a join PhieuThanhLy b on a.MaNV=b.MaNV " +
                         "join CTPhieuTL c on b.MaPhieuTL=c.MaPhieuTL " +
                         "join BanSach d on c.MaBanSach=d.MaBanSach " +
                         "join DauSach e on d.MaDauSach=e.MaDauSach " +
                         "join TacGia f on e.MaTacGia=f.MaTacGia " +
                         "join LoaiSach g on e.MaLoaiSach=g.MaLoaiSach " +
                         "where b.MaPhieuTL=N'" + maphieutl + "' " +
                         "order by MaBanSach";
            return conn.GetDataTable(sql);
        }
        DataTable getSource_DuToan(string madt)
        {
            string sql = "select b.MaPhieuDuToan, Upper(TenPhieu) as TenPhieu,NgayLap,TenNV,MaLoaiSach as KhoSach,TenDauSach,SoLuong,DonGia, SoLuong*DonGia as 'ThanhTien' " +
                         "from NhanVien a join PhieuDuToan b on a.MaNV=b.MaNV " +
                         "join CTPhieuDuToan c on b.MaPhieuDuToan=c.MaPhieuDuToan " +
                         "where b.MaPhieuDuToan=N'"+madt+"'";
            return conn.GetDataTable(sql);
        }
    }
}
